#include <stdio.h>
#include <string.h>

struct student { 
	long long num;
    char name[50];
    double score;
};

typedef struct stu {
    int ID;
    char name[20];
    char sex;
    int age;
    double score;
}pStu;

void firstReport();
void secondReport();

int main() {
    firstReport();
    secondReport();
    return 0;
}

void firstReport() {
	int i;
	struct student st,stmax,stmin;
	stmax.score=0;  stmin.score=100;
    for(i = 0; i < 10; i ++) {
	    printf("input  data <ID> <Name> <Score>:\t");
		scanf("%lld%s%lf",&st.num,st.name,&st.score);
		if(st.score>stmax.score) 
			stmax=st;
		if(st.score<stmin.score) 
			stmin=st;
	}
	printf("\nhight:%lld\t%s\t%lf\n",stmax.num,stmax.name,stmax.score);
	printf("\nlow:%lld\t%s\t%lf\n",stmin.num,stmin.name,stmin.score);
}

void secondReport() {
    int i, j;
    const short N = 10; //#define N 10
    pStu stuList[N], tmpStruct;
    pStu *pList = stuList;
    int IDList[] = {101, 102, 103, 104, 105, 106, 107, 108, 109, 110};
    char nameList[][8] = {"Zhang", "Wang", "Zhao", "Li", "Gao", "Lin", "Ma", "Zhen", "Xu", "Mao"};
    char sexList[] = {'M', 'F', 'M', 'M', 'M', 'M', 'F', 'M', 'M', 'F'};
    int ageList[] = {19, 18, 19, 20, 19, 18, 18, 21, 19, 22};
    double scoreList[] = {95.6, 92.2, 85.7, 96.3, 90.2, 91.2, 98.7, 88.7, 90.1, 94.7};
    for(i = 0; i < N; i ++) {
        (*(pList + i)).ID = IDList[i];
        strcpy((*(pList + i)).name, nameList[i]);
        (*(pList + i)).sex = sexList[i];
        (*(pList + i)).age = ageList[i];
        (*(pList + i)).score = scoreList[i];
    }
    printf("\n****\tbefore Changed:\t\t****\n\n");
    printf("ID\tName\tSex\tAge\tScore\n");
    for(i = 0; i < N; i ++) {
        printf("%d\t", (*(pList + i)).ID);
        printf("%s\t", (*(pList + i)).name);
        printf("%c\t", (*(pList + i)).sex);
        printf("%d\t", (*(pList + i)).age);
        printf("%2.1lf\n", (*(pList + i)).score);
    }
    for(i = 0; i < N; i ++) {
        for(j = i + 1; j < N; j ++) {
            if((*(pList + i)).score < (*(pList + j)).score) {
                tmpStruct = *(pList + i);
                *(pList + i) = *(pList + j);
                *(pList + j) = tmpStruct;
            }
        }
    }
    printf("\n****\t after Changed:\t\t****\n\n");
    printf("ID\tName\tSex\tAge\tScore\n");
    for(i = 0; i < N; i ++) {
        printf("%d\t", (*(pList + i)).ID);
        printf("%s\t", (*(pList + i)).name);
        printf("%c\t", (*(pList + i)).sex);
        printf("%d\t", (*(pList + i)).age);
        printf("%2.1lf\n", (*(pList + i)).score);
    }
    printf("\n****\t\tEND\t\t****\n\n");
}
